/********************************************************************
filename : wolf_iic_MMA7455L.h
discript : dreamwolf on board Accelerometer(MMA7455L) control driver,
					 device address is:0b0011101x,pin connect as below:
					 IIC_SDA  -> PB7,
					 IIC_CLK  -> PB6,
					 CS       -> PF8,
					 DRDY     -> PF9,
					 ADDR0    -> GND.
version  : V0.0
editor   : Icy - dreamwolf
time     : 2014.3.2
statement: This file is modified by dreamwolf under LGPL,you could use 
           it free.We cann't ensure there is no error in this file,and
				   if you detect an error please contact us freely,it is so a-
					 ppreciate for your help to improve our code that could help 
					 more people to use it safty.
contact  : edreamtek@163.com
           www.edreamtek.com
********************************************************************/

#ifndef __WOLF_IIC_MMA7455L_H__
#define __WOLF_IIC_MMA7455L_H__

#include "stm32f0xx.h"
#include "wolf_typedefine.h"
#include "wolf32f031_board_pinmap.h"
#include "wolf_iic1_common.h"

typedef struct{
	uint16_t	X_dat;
	uint16_t	Y_dat;
	uint16_t	Z_dat;
}MMA7455_CPT_DATA;								/*complement data*/

typedef struct{
	int16_t	X_dat;
	int16_t	Y_dat;
	int16_t	Z_dat;
}MMA7455_DATA;								/*true form data*/


#define MMA7455_HW_ADDRESS        0x3A   /* ADDR0 = 0 */ 

#define MMA7455_REG_CNT						0x1E


#define XOUTL											0x00
#define XOUTH											0x01
#define YOUTL											0x02
#define YOUTH											0x03
#define ZOUTL											0x04
#define ZOUTH											0x05
#define XOUT8											0x06
#define YOUT8											0x07
#define ZOUT8											0x08
#define STATUS										0x09
#define DETSRC										0x0A
#define TOUT											0x0B
#define IICAD											0x0D
#define USRING										0x0E
#define WHOAMI										0x0F
#define XOFFL											0x10
#define XOFFH											0x11
#define YOFFL											0x12
#define YOFFH											0x13
#define ZOFFL											0x14
#define ZOFFH											0x15
#define MCTL											0x16
#define INTRST										0x17
#define CTL1											0x18
#define CTL2											0x19
#define LDTH									 		0x1A
#define PDTH									 		0x1B
#define PW								 				0x1C
#define LT									 			0x1D
#define TW									 			0x1E

#define DAT_10_BITS								10
#define DAT_8_BITS								8

#define DAT_10_MASK								0x1FF
#define DAT_8_MASK								0x7F


#define 	MMA7455_CS_HIGH()		MMA7455_CS_GPIO_PORT->BSRR = MMA7455_CS_PIN  
#define 	MMA7455_CS_LOW()		MMA7455_CS_GPIO_PORT->BRR = MMA7455_CS_PIN  


extern uint8_t MMA7455_reg[MMA7455_REG_CNT]; 
extern MMA7455_CPT_DATA MMA7455_cpt_dat;
extern MMA7455_DATA MMA7455_dat;


  

void wolf_iic_MMA7455_init(void);

void wolf_iic_MMA7455_read_data(uint8_t dat_length);

void wolf_iic_MMA7455_true_form_data(uint8_t length);

void wolf_iic_MMA7455_write_byte(uint16_t addr,uint8_t dat);

uint8_t wolf_iic_MMA7455_read_byte(uint32_t addr);

void wolf_iic_MMA7455_write_bytes(uint16_t addr,uint8_t* pdat,uint16_t cnt);

void wolf_iic_MMA7455_read_bytes(uint32_t addr,uint8_t* pdat,uint16_t cnt);

void wolf_iic_MMA7455_read_register(void);






#endif

